namespace CSharpPro._1016;

public class Demo
{
    public void TestPrint()
    {
        Console.WriteLine("三个整数由小到大输出");
        Console.Write("请输入三个整数x、y、z，用空格分隔：");
        string[] inputNums = Console.ReadLine().Split();
        int x = int.Parse(inputNums[0]);
        int y = int.Parse(inputNums[1]);
        int z = int.Parse(inputNums[2]);
        int[] sortedNums = { x, y, z };
        Array.Sort(sortedNums);
        Console.WriteLine($"排序结果：{sortedNums[0]} {sortedNums[1]} {sortedNums[2]}\n");
    }
    public void TestPrint1()
    {
        Console.WriteLine("1-100之间所有不是7的倍数和不包含7的数字");
        int sum = 0;
        List<int> validNumbers = new List<int>();
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                validNumbers.Add(i);
                sum += i;
            }
        }
        Console.WriteLine("符合条件的数字：" + string.Join(" ", validNumbers));
        Console.WriteLine("这些数字的和：" + sum + "\n");
    }
    public void TestPrint2()
    {
        Console.WriteLine("九九乘法表");
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }
            Console.WriteLine();
        }
        Console.WriteLine();
    }
    public void TestPrint3()
    {
        Console.WriteLine("1000以内的所有完数");
        for (int i = 2; i <= 1000; i++)
        {
            int factorSum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    factorSum += j;
                }
            }
            if (factorSum == i)
            {
                Console.Write(i + " ");
            }
        }
        Console.WriteLine("\n");
    }
    public void TestPrint4()
    {
        Console.WriteLine("分析正整数");
        Console.Write("请输入一个正整数：");
        int num = int.Parse(Console.ReadLine());
        string numStr = num.ToString();
        Console.WriteLine($"它是{numStr.Length}位数");
        Console.Write("逆序打印各位数字：");
        for (int i = numStr.Length - 1; i >= 0; i--)
        {
            Console.Write(numStr[i] + " ");
        }
        Console.WriteLine("\n");
    }
    public void TestPrint5()
    {
        Console.WriteLine("打印菱形");
        Console.Write("请输入菱形的行数（奇数）：");
        int rows = int.Parse(Console.ReadLine());
        if (rows % 2 == 0)
        {
            Console.WriteLine("请输入奇数行数！");
            return;
        }
        
        int half = rows / 2;
        for (int i = 0; i <= half; i++)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        for (int i = half - 1; i >= 0; i--)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }
            
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }
    }
}